<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>$Title$</title>
</head>
<script src="../static/js/jquery-1.8.2.min.js"></script>
<link rel="stylesheet" href="../static/css/css.css">
<body>
<form>
    姓名：<input type="text" name="userName" th:value="${vo.userName}">
    <input type="submit" value="查询">
</form>
<input type="button" value="注册用户" th:onclick="add()">
<table>
    <tr>
        <td>用户id</td>
        <td>用户名</td>
        <td>用户密码</td>
        <td>真实姓名</td>
        <td>电子邮件</td>
        <td>联系电话</td>
        <td>备注</td>
        <td>冻结状态</td>
        <td>注册日期</td>
        <td>性别</td>
        <td>爱好</td>
        <td>操作</td>
    </tr>
    <tr th:each="list:${list}">
        <td th:text="${list.usersId}"></td>
        <td th:text="${list.userName}"></td>
        <td th:text="${list.password}"></td>
        <td th:text="${list.trueName}"></td>
        <td th:text="${list.email}"></td>
        <td th:text="${list.phone}"></td>
        <td th:text="${list.comments}"></td>
        <td th:text="${list.lockState}"></td>
        <td th:text="${list.registerDate}"></td>
        <td th:text="${list.sex}"></td>
        <td th:text="${list.love}"></td>
        <td>
            <input type="button" value="修改" th:onclick="toupd([[${list.usersId}]])">
            <input type="button" value="删除" th:onclick="del([[${list.usersId}]])">
            <input type="button" value="详情" th:onclick="info([[${list.usersId}]])">
        </td>
    </tr>
    <tr>
        <td colspan="11">
            <input type="button" value="首页" th:onclick="page(1)">
            <input type="button" value="上一页" th:onclick="page([[${pu.getPrevPage()}]])">
            <input type="button" value="下一页" th:onclick="page([[${pu.getNextPage()}]])">
            <input type="button" value="尾页" th:onclick="page([[${pu.getTotalPage()}]])">
            当前[[${pu.getCurrentPage()}]]页/共[[${pu.getTotalPage()}]]页
        </td>
    </tr>
</table>
</body>
<script>
    function info(id) {
        location = "toInfo?id="+id;
    }
    function page(pageNum) {
        var userName = $("[name=userName]").val();
        location = "list?pageNum="+pageNum+"&userName="+userName
    }
    function add() {
        location = "toadd";
    }
    function toupd(id) {
        location = "toupd?uid="+id;
    }
    function del(id) {
        if(confirm("您确认要删除该用户吗？")){
            $.ajax({
                url:"del",
                type:"post",
                data:{id},
                dataType:"json",
                success:function (obj) {
                    if (obj == 1) {
                        alert(("删除成功！"))
                        location = "list";
                    }else {
                        alert("删除失败！");
                    }
                }
            })
        }
    }
</script>
</html>